package com.sg.business.commons.field;

import org.eclipse.ui.forms.IFormPart;

import com.sg.business.commons.ui.vault.DocumentUIUtils;
import com.sg.business.model.Document;
import com.sg.widgets.MessageUtil;
import com.sg.widgets.part.editor.PrimaryObjectEditorInput;
import com.sg.widgets.part.editor.fields.value.IFieldActionHandler;

public class ViewPLM implements IFieldActionHandler {

	public ViewPLM() {
	}

	@Override
	public Object run(IFormPart abstractFieldPart,
			PrimaryObjectEditorInput input) {
		Document document = (Document) input.getData();
		try {
			DocumentUIUtils.viewContent(document);
		} catch (Exception e) {
			MessageUtil.showToast(e);
		}
		return null;
	}

	public String getURL(Object data) {
		if (data instanceof Document) {
			return ((Document) data).getPLMObjectInformationURL();
		}
		return null;
	}

	public String getOid(Object data) {
		if (data instanceof Document) {
			return ((Document) data).getPLMObjectInformationOid();
		}
		return null;
	}

}
